//
//  DMDiseaseView.m
//  CQKuaiYi
//
//  Created by Mr.Cannon on 2017/1/8.
//  Copyright © 2017年 Mr.Cannon. All rights reserved.
//

#import "DMDiseaseView.h"
#import "DMAppointmentController.h"
typedef enum
{
    DiseaseTumour = 1,
    DiseaseBlood,
    DiseasePainstaking,
    DiseaseNerve,
    DiseaseOrthopedics,
    DiseaseCommonweal
}DiseaseTag;
@implementation DMDiseaseView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
#pragma mark - 初始化界面
-(void)setupUI
{
    //创建按钮
    //肿瘤
    UIButton* tumourBtn = [[UIButton alloc]init];
    //血液
    UIButton* bloodBtn = [[UIButton alloc]init];
    //心血
    UIButton* painstakingBtn = [[UIButton alloc]init];
    //神经
    UIButton* nerveBtn = [[UIButton alloc]init];
    //骨科
    UIButton* orthopedicsBtn = [[UIButton alloc]init];
    //公益活动
    UIButton* commonwealBtn = [[UIButton alloc]init];
    //分割视图
    UIView* centerView = [[UIView alloc]init];
    UIView* top1 = [[UIView alloc]init];
    UIView* top2 = [[UIView alloc]init];
    UIView* botton1 = [[UIView alloc]init];
    UIView* botton2 = [[UIView alloc]init];
    //设置view颜色
    top1.backgroundColor = DMRGBCOLOR;
    top2.backgroundColor = DMRGBCOLOR;
    botton1.backgroundColor = DMRGBCOLOR;
    botton2.backgroundColor = DMRGBCOLOR;
    centerView.backgroundColor = DMRGBCOLOR;
    //设置图片
    [tumourBtn setBackgroundImage:[UIImage imageNamed:@"01"] forState:UIControlStateNormal];
    //    tumourBtn.backgroundColor = [UIColor redColor];
    [bloodBtn setBackgroundImage:[UIImage imageNamed:@"02"] forState:UIControlStateNormal];
    [painstakingBtn setBackgroundImage:[UIImage imageNamed:@"03"] forState:UIControlStateNormal];
    [nerveBtn setBackgroundImage:[UIImage imageNamed:@"04"] forState:UIControlStateNormal];
    [orthopedicsBtn setBackgroundImage:[UIImage imageNamed:@"05"] forState:UIControlStateNormal];
    [commonwealBtn setBackgroundImage:[UIImage imageNamed:@"06"]forState:UIControlStateNormal];
    //添加到视图中
    [self addSubview:tumourBtn];
    [self addSubview:bloodBtn];
    [self addSubview:painstakingBtn];
    [self addSubview:nerveBtn];
    [self addSubview:orthopedicsBtn];
    [self addSubview:commonwealBtn];
    [self addSubview:centerView];
    [self addSubview:top1];
    [self addSubview:top2];
    [self addSubview:botton1];
    [self addSubview:botton2];
    //布局
    CGRect rect = [UIScreen mainScreen].bounds;
    CGFloat width = rect.size.width / 3;
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.width.mas_equalTo(rect.size.width);
        make.height.mas_equalTo(0.25);
    }];
    [tumourBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(0);
        make.top.equalTo(self.mas_top);
        make.width.mas_equalTo(width - 0.5);
        make.bottom.equalTo(centerView.mas_top);
    }];
    [top1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tumourBtn.mas_right);
        make.width.mas_equalTo(0.5);
        make.top.equalTo(self.mas_top).offset(15);
        make.bottom.equalTo(centerView.mas_top).offset(-15);
    }];
    [bloodBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(top1);
        make.width.mas_equalTo(width);
        make.bottom.equalTo(centerView);
        make.top.equalTo(self);
    }];
    [top2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bloodBtn.mas_right);
        make.width.mas_equalTo(0.5);
        make.top.equalTo(self.mas_top).offset(15);
        make.bottom.equalTo(centerView.mas_top).offset(-15);
    }];
    [painstakingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(top2);
        make.width.mas_equalTo(width - 0.5);
        make.bottom.equalTo(centerView);
        make.top.equalTo(self);
    }];
    [nerveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(centerView);
        make.bottom.equalTo(self);
        make.left.equalTo(self);
        make.width.mas_equalTo(width-0.5);
    }];
    [botton1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nerveBtn.mas_right);
        make.width.mas_equalTo(0.5);
        make.top.equalTo(centerView.mas_bottom).offset(15);
        make.bottom.equalTo(self).offset(-15);
    }];
    [orthopedicsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(centerView);
        make.bottom.equalTo(self);
        make.left.equalTo(botton1);
        make.width.mas_equalTo(width);
    }];
    [botton2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(orthopedicsBtn.mas_right);
        make.width.mas_equalTo(0.5);
        make.top.equalTo(centerView.mas_bottom).offset(15);
        make.bottom.equalTo(self).offset(-15);
    }];
    [commonwealBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(centerView);
        make.bottom.equalTo(self);
        make.left.equalTo(botton2);
        make.width.mas_equalTo(width);
    }];
    //设置tag
    tumourBtn.tag = DiseaseTumour;
    bloodBtn.tag = DiseaseBlood;
    painstakingBtn.tag = DiseasePainstaking;
    nerveBtn.tag = DiseaseNerve;
    orthopedicsBtn.tag = DiseaseOrthopedics;
    commonwealBtn.tag = DiseaseCommonweal;
    //添加事件
    /*
     [self addSubview:tumourBtn];
     [self addSubview:bloodBtn];
     [self addSubview:painstakingBtn];
     [self addSubview:nerveBtn];
     [self addSubview:orthopedicsBtn];
     [self addSubview:commonwealBtn];
     */
    [tumourBtn addTarget:self action:@selector(diseaseClick:) forControlEvents:UIControlEventTouchUpInside];
    [bloodBtn addTarget:self action:@selector(diseaseClick:) forControlEvents:UIControlEventTouchUpInside];
    [painstakingBtn addTarget:self action:@selector(diseaseClick:) forControlEvents:UIControlEventTouchUpInside];
    [nerveBtn addTarget:self action:@selector(diseaseClick:) forControlEvents:UIControlEventTouchUpInside];
    [orthopedicsBtn addTarget:self action:@selector(diseaseClick:) forControlEvents:UIControlEventTouchUpInside];
    [commonwealBtn addTarget:self action:@selector(diseaseClick:) forControlEvents:UIControlEventTouchUpInside];
    
}
#pragma mark: - 疾病入口
-(void)diseaseClick:(UIButton*)sender
{
    if(![self respondsToSelector:@selector(disease:andTag:)])
    {
        [self.delegate disease:self andTag:sender.tag];
        NSLog(@"%zd",sender.tag);
    }
}
#pragma mark: - 公益活动
-(void)orthopedicsClick:(UIButton*)sender
{
    
}
@end
